<template>
  <view class="content">
    <block v-if="item">
      <view class="top-img">
        <image :src="this.$store.state.imgBaseUrl + '/join-big-1.png'" v-if="item.status == 0 "></image>
        <image :src="this.$store.state.imgBaseUrl + '/join-big-2.png'" v-if="item.status != 0 && item.status != 1"></image>
        <image :src="this.$store.state.imgBaseUrl + '/store-1.png'" v-if="item.status == 1"></image>
      </view>
      <view class="r-text">
        <text v-if="item">
          {{item.statusName}}
        </text>
      </view>
      <view class="hint" v-if="item.status == 0">
        请耐心等待1-2个工作日，我们会尽快为您审核，请留意您的短信或系统通知！
      </view>
      <view class="hint" v-if="item.status != 0 && item.status != 1">
        <view>{{item.userQualification2mVo.remark}}</view>
        <view v-if="item.appliedType != 1">{{item.accountTransferVo.ideaRemark}}</view>
      </view>
      <view class="icon-list" v-if="item">
        <view class="box" :class="{over: item.userQualification2mVo.status != 0}">
          <image src="../../static/image/join-sm-2.png" v-if="item.userQualification2mVo.status == 0"></image>
          <image src="../../static/image/join-sm-1.png" v-if="item.userQualification2mVo.status == 1"></image>
          <image src="../../static/image/join-sm-3.png" v-if="item.userQualification2mVo.status == 2 || item.userQualification2mVo.status == 3"></image>
          <view>
            资质认证
          </view>
        </view>
        <block v-if="item.appliedType != 1">
          <view class="line"></view>
          <view class="box" :class="{over: item.accountTransferVo.status != 0}">
            <image src="../../static/image/join-sm-2.png" v-if="item.accountTransferVo.status == 0"></image>
            <image src="../../static/image/join-sm-1.png" v-if="item.accountTransferVo.status == 1"></image>
            <image src="../../static/image/join-sm-3.png" v-if="item.accountTransferVo.status == 2 || item.accountTransferVo.status == 3"></image>
            <view>
              费用缴纳
            </view>
          </view>
        </block>
      </view>
      <view class="footer" v-if="item.status != 0 && item.status != 1">
        <button type="primary" class="sub-btn cur" plain="true" @click="draw">重新申请</button>
      </view>
      <view class="footer" v-if="item.status == 1">
        <button type="primary" class="sub-btn cur" plain="true" @click="gotoHome">返回首页</button>
      </view>
    </block>
  </view>
</template>
<script>
import { reviewQualification, findResult } from '@/service/join/join.service.js'
export default {
  data() {
    return {
      title: {
        0: '审核中',
        1: '审核通过',
        2: '市场失败',
        3: '财务失败',
        4: '市场驳回',
        5: '财务驳回',
        6: '市场财务均驳回'
      },
      item: null,
      userInfo: ''
    };
  },
  onShow:function() {
    let recomObj = uni.getStorageSync('recomposeDatas');
    if (recomObj) {
      uni.removeStorageSync('recomposeDatas');
    }
    this.getInfo();
  },
  methods: {
    gotoHome () {
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    getInfo () {
      findResult({}, (res) => {
        if (res.status == 0) {
          if (res.data) { // 已申请过加盟
            uni.setNavigationBarTitle({
              title: this.title[res.data.status]
            })
            this.item = res.data;
            if (res.data.status == 1 && res.data.upgradeRank > 1) { // 审核成功去首页
              uni.switchTab({
                url: '/pages/index/index'
              })
            }
            // 付款失败
            if (this.item.accountTransferVo) {
              if (this.item.accountTransferVo.onlinePay == 1 && this.item.accountTransferVo.status == 0 && this.item.accountTransferVo.transferImages.length == 0) {
                let datas = {
                  rank: this.item.upgradeRank,
                  transferImages: this.item.accountTransferVo.transferImages, // 存储凭证信息
                  remark: this.item.accountTransferVo.remark ,// 存储备注
                  joinId: this.item.id // 存储加盟id
                }
                uni.setStorage({ // 存储加盟信息
                  key: 'recomposeDatas',
                  data: datas, // 资质信息
                  success: () => {
                    uni.reLaunch({
                      url: '/pages/upgrade/payFail'
                    })
                  }
                })
              }
            }
          } else { // 未申请加盟去加盟入住页
            uni.redirectTo({
              url: '/pages/join/index'
            })
          }
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
      })
    },
    draw () {
      /**
      this.item.status: 0待审核 1审核通过
            2资质审核失败 3财务审核失败
            4资质驳回 5财务驳回 6市场财务均驳回
      **/
      let info = {
        rank: this.item.upgradeRank,
        joinId: this.item.id
      }
      if (this.item.accountTransferVo) {
        info['transferImages'] = this.item.accountTransferVo.transferImages; // 上传凭证的图片
        info['remark'] = this.item.accountTransferVo.remark; // 上传凭证的备注
      }
      if (this.item.status == 2 || this.item.status == 3) {
        this.userInfo = this.$store.state.userInfo;
        let datas = {
          href: this.userInfo.href,
          nickName: this.userInfo.nickName,
          vipExpireDate: this.userInfo.vipExpireDate,
          rank: this.item.currentRank
        }
        uni.setStorage({ // 存储加盟信息
          key: 'gradeUserInfo',
          data: datas, // 资质信息
          success: () => {
            uni.navigateTo({
              url: '/pages/upgrade/index?status=1' 
            })
          }
        })
      } else if (this.item.status == 5) { // 财务审核驳回
        uni.setStorage({ // 存储加盟信息
          key: 'recomposeDatas',
          data: info, // 资质信息
          success: () => {
            uni.navigateTo({
              url: '/pages/upgrade/updateCertificate'
            })
          }
        }) 
      }
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  height: 100vh;
  background-color: #FFFFFF;
}
image {
  width: 100%;
  height: 100%;
}
.result {
  padding-top: 40rpx;
  height: 100vh;
  background-color: #FFFFFF;
}
.top-img {
  width: 330rpx;
  height: 330rpx;
  margin: 0 auto 30rpx;
}
.r-text {
  text-align: center;
  font-size: 36rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
}
.hint {
  font-size: 30rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #999999;
  margin-top: 52rpx;
  text-align: center;
  padding: 0 60rpx;
  line-height: 1.6;
}
.icon-list {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 150rpx;
  .box {
    color: #999999;
    font-size: 29rpx;
    image {
      display: block;
      width: 51rpx;
      height: 51rpx;
      margin: 0 auto 25rpx;
    }
    &.over {
      color: #434343;
    }
  }
  .line {
    width: 87rpx;
    height: 1px;
    background: #E1E1E1;
    margin-left: 18rpx;
    margin-right: 29rpx;
  }
}
.footer {
  width: 100%;
  border-top: 1px solid #E1E1E1;
  padding: 14rpx 0 20rpx;
  background-color: #FFFFFF;
  position: absolute;
  bottom: 0;
  left: 0;
  button {
    height: 70rpx;
    margin: 0 32rpx;
    background-color: #636363;
    font-size: 30rpx;
    line-height: 70rpx;
    color: #ADA697;
    border: none;
    &.cur {
      color: #F6DA99;
      background-color: #434343;
    }
  }
}
</style>
